package puyu.manage.service.utils.except;

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

public class ExceptionFormatter {
    private String filter = "puyu.manage";
    private int traceDepth = 3;
    private Exception _e;
    private StackTraceElement _stElement;
    private StackTraceElement[] _stElements;
    private String _className;
    private String _fileName;
    private String _methodName;
    private int _lineNumber;

    public ExceptionFormatter(Exception e) {
        this._e = e;
        this._stElements = this.getStackElements();
        this._stElement = this._stElements[0];
        if (this._stElement != null) {
            this._fileName = this._stElement.getFileName();
            this._className = this._stElement.getClassName();
            this._methodName = this._stElement.getMethodName();
            this._lineNumber = this._stElement.getLineNumber();
        }

    }

    public String getErrorMessage() {
        return this._e.getMessage();
    }

    public String getClassName() {
        return this._className;
    }

    public String getFileName() {
        return this._fileName;
    }

    public String getMethodName() {
        return this._methodName;
    }

    public int getLineNumber() {
        return this._lineNumber;
    }

    public String getStackMessage() {
        StringBuffer sb = new StringBuffer();
        sb.append("错误原因：").append(this._e.getMessage()).append("\n");
        StackTraceElement stElement = null;

        for(int i = 0; i < this._stElements.length; ++i) {
            stElement = this._stElements[i];
            if (stElement == null) {
                break;
            }

            sb.append(" 在 ").append(stElement).append("\n");
        }

        return sb.toString();
    }

    public String toString() {
        return this.getStackMessage();
    }

    private StackTraceElement[] getStackElements() {
        StackTraceElement[] stElements = this._e.getStackTrace();
        StackTraceElement[] returnStElements = new StackTraceElement[this.traceDepth];
        StackTraceElement stElement = null;
        int i = 0;

        for(int j = 0; i < stElements.length && j < this.traceDepth; ++i) {
            stElement = stElements[i];
            if (stElement.getClassName().startsWith(this.filter)) {
                returnStElements[j] = stElement;
                ++j;
            }
        }

        return returnStElements;
    }
}
